home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 25 / Mac Magazin and MacEasy Magazine CD - Issue 25.iso / Grafik & Text / BibTeX / Source code / bibutils.h < prev    next >
C/C++ Source or Header  |  1996-02-18  |  8KB  |  268 lines

  1. #pragma once
  2.  
  3. #if (__STDC__ || defined(__cplusplus))
  4. #define STDC            1
  5. #else
  6. #define STDC            0
  7. #endif
  8.  
  9. #include <stdio.h>
  10. #include <ctype.h>
  11.  
  12. typedef struct FileDesc {
  13.     FSSpec  spec;
  14.     short   refNum;
  15. } FileDesc, *FileDescPtr;
  16. //typedef struct FileDesc FileDesc, * FileDescPtr;
  17. extern int              verbose;
  18.  
  19. #define MISSING_UNISTD_H
  20. #define ENV_SEPAR ':'
  21. #define DIR_DELIM ':'
  22. #define access(fn, mode) 0              /* function not available */
  23. #define kBufferSize 2048                /* for output buffer */
  24. #define kReadBufferSize 1024            // for read buffer
  25. #define FSEEK FSeek
  26. #define UNGETC UnGetC
  27. #define     Min(x, y)       ((x) < (y) ? (x) : (y))
  28. void    CloseAllFiles(void);
  29. void    FatalOSErr(const char *mess, OSErr error);
  30. void    FatalOSErr(const char *mess, const char *mess1, OSErr error);
  31. void    FormatOSErr(OSErr error, char *buffer);
  32. void    GetWindowTitle(StringPtr outName);
  33. long    GetIdxCharacter(void);
  34. void    InitializeGenInd(void);
  35. void    InitializeScanId(void);
  36. void    InitializeScanSt(void);
  37. void    IntroduceBtxFile(FSSpecPtr specPtr);
  38. void    InvokeBibtex(void);
  39. OSErr   OneTimeInitialization(void);
  40. void    SetBibtexOptions(Boolean debugOn);
  41. void    GetBibtexOptions(Boolean& debugOn);
  42. void    ReportOSErr(const char *mess, OSErr error);
  43.  
  44. #define STDC_PROTOTYPES 1
  45.  
  46. #if    STDC_PROTOTYPES
  47. #define ARGS(arg_list)  arg_list
  48. #define VOIDP           void*
  49. #define VOID_ARG        void
  50. #else
  51. #define ARGS(arg_list)  ()
  52. #undef const
  53. #define const
  54. #define VOIDP           char*
  55. #define VOID_ARG
  56. #endif
  57.  
  58.  
  59. #define FREE(p) free((void*)(p))
  60.  
  61. #if    STDC
  62. #include <stdlib.h>
  63. #undef strchr
  64. #undef strrchr
  65. #include <string.h>
  66.  
  67. #if !defined(MISSING_UNISTD_H)
  68. #include <unistd.h>
  69. #endif
  70.  
  71. #else /* NOT STDC */
  72.         /* Miscellaneous standard library routines */
  73.  
  74. #if !defined(access)
  75. int     access ARGS((const char *, int));
  76. #endif
  77.  
  78. VOIDP   calloc ARGS((size_t nitems,size_t size));
  79.  
  80. char   *getenv (const char *name);
  81.  
  82. VOIDP   malloc ARGS((size_t size));
  83. char   *strchr ARGS((const char *s,int c));
  84. char   *strrchr ARGS((const char *s,int c));
  85. #endif /* STDC */
  86.  
  87. #ifndef    R_OK
  88. #define R_OK            4               /* only symbol from sys/file.h */
  89. #endif
  90.  
  91. #undef TRUE
  92. #define TRUE            1
  93.  
  94. #undef FALSE
  95. #define FALSE           0
  96.  
  97. #undef NUL
  98. #define NUL             '\0'
  99.  
  100. #undef NIL
  101. #define NIL             ""
  102.  
  103. #define TAB             '\t'
  104. #define LFD             '\r'
  105. #define SPC             ' '
  106. #define LSQ             '['
  107. #define BSH             '\\'
  108.  
  109. #ifndef SW_PREFIX                       /* can override at compile time */
  110. #define SW_PREFIX       '-'
  111. #endif
  112.  
  113. #define EXT_DELIM       '.'
  114.  
  115. #define GET_CHAR        GetC
  116.  
  117. /* Use our own versions of IsLower() and IsUpper so Makeindex will be faster */
  118.  
  119. #define ISLOWER(c)      IsLower(c)
  120. #define ISUPPER(c)      IsUpper(c)
  121.  
  122. /*
  123.     If C is alphabetic, Bibtex expects the result of TOLOWER or TOUPPER to
  124.     be an unaccented alphabetic character.  That\'s why it is necessary to call
  125.     ToStrip before doing the case conversion.  The casts are very important!
  126. */
  127.  
  128. #define TOLOWER(C) ((unsigned char) ToLower(ToStrip((unsigned char)(C))))
  129. #define TOUPPER(C) ((unsigned char) ToUpper(ToStrip((unsigned char)(C))))
  130.  
  131. #define STREQ(A, B)     (strcmp(A, B) == 0)
  132. #define STRNEQ(A, B)    (strcmp(A, B) != 0)
  133.  
  134. #define MESSAGE(F, S) { \
  135.     if (verbose) \
  136.         (void)FPrintFStdErr( F, S); \
  137. }
  138.  
  139. #define FATAL(F, S) { \
  140.     (void)FPrintFStdErr( F, S); \
  141.     throw NULL; \
  142. }
  143.  
  144. #define FATAL2(F, D1, D2) { \
  145.     (void)FPrintFStdErr( F, D1, D2); \
  146.     throw NULL; \
  147. }
  148.  
  149. // #ifdef FCLOSE
  150. // #undef FCLOSE
  151. // #endif
  152. // #define FCLOSE(FREF,SPECPTR)     CloseFile(FREF,SPECPTR)
  153. // #define CLOSE(FREF,SPECPTR)     CloseFile(FREF,SPECPTR)
  154. #define OPEN_IN(FP)   OpenInputFile(FP)
  155. #define OPEN_OUT(FP)  OpenOutputFile(FP)
  156. #define REOPEN_OUT(FN,FP) freopen(FN,"w",FP)
  157.  
  158. /*====================================================================*/
  159.  
  160. #define VERSION       "MacOS version 1.0 [18-Feb-1996]"
  161.  
  162. #if 0
  163. #endif
  164.  
  165. #define PUT_VERSION { \
  166.     MESSAGE("This is %s, ", pgm_fn); \
  167.     MESSAGE("%s.\r", VERSION); \
  168.     need_version = FALSE; \
  169. }
  170.  
  171. #define USAGE \
  172.    "Usage: %s [-c] [-d] [-e errfile] [-g] [-i] [-l] [-o ind] [-p num] \r\
  173. \t\t[-q] [-r] [-s sty] [-t log] [idxfile0 idxfile1 ...]\r"
  174.  
  175. #define STYLE_PATH "BIBTEXSTYLE" /* environment variable defining search */
  176.                                 /* path for style files */
  177. #define BIBTEX_INP       ".aux"
  178. #define BIBTEX_BLG       ".blg"
  179. #define BIBTEX_BIB       ".bib"
  180. #define BIBTEX_STY       ".bst"
  181. #define BIBTEX_BBL       ".bbl"
  182. #define BIBTEX_DBG       ".dbg"
  183.  
  184. /*
  185. #if !defined(BIBTEX_LOG)
  186. #define BIBTEX_LOG       ".log"
  187. #endif
  188. */
  189.  
  190.  
  191. /***********************************************************************
  192.  
  193. BibTeX 0.99c: Since we really never have to repeatedly allocate and
  194. free dynamic string storage, we use chkalloc() to allocate it with
  195. less storage overhead than malloc(), by using malloc() to get large
  196. chunks within which we suballocate small chunks using just the storage
  197. that they need, subject to alignment requirements.  At job
  198. termination, we free the large chunks with chkfree(), so that there
  199. are no untidy memory leaks.  All storage allocation in Bibtex 0.99c
  200. or later uses chkalloc() instead of malloc().
  201.  
  202. We further reduce storage requirements by storing only the page
  203. numbers that are actually used, in structures of type PAGE_PARTS.  In
  204. order to support page number strings of mixed arabic and alphabetic
  205. characters, such as 120A, 120B, ..., we store the original page number
  206. string in the page[] array of PAGE_PARTS.  Although that structure
  207. declares the page[] array of 1 character, don't believe that size.  We
  208. actually allocate as many characters as are needed, in the ENTER()
  209. macro in scanid.h.  The structure names in PAGE_PARTS merely provide
  210. convenient handles to access the various fields.  Integer storage
  211. alignment requirements will require allocating each PAGE_PARTS
  212. structure on a suitable boundary, but that can be conveniently hidden
  213. inside chkalloc().
  214.  
  215. ***********************************************************************/
  216.  
  217. #define DOT             "."
  218. #define DOT_MAX         1000 /* progress dot interval in gen_ind(), scan_idx()*/
  219. #define CMP_MAX         1000 /* progress dot interval in sort stage */
  220.  
  221. /* Macro to print a dot every MAX invocations */
  222. #define IDX_DOT(MAX) { \
  223.     BibTeX_dot = TRUE; \
  224.     if (BibTeX_dc++ == 0) { \
  225.         if (verbose) \
  226.             (void)FPrintFStdErr( DOT); \
  227.         (void) FPrintF(&gBlgDesc, DOT); \
  228.     } \
  229.     if (BibTeX_dc == MAX) \
  230.         BibTeX_dc = 0; \
  231. }
  232.  
  233. #define STATIC                          /* empty definition => automatic */
  234.  
  235. #define ALL_DONE { \
  236.     if (fn_no > 0) { \
  237.         if (verbose) \
  238. (void)FPrintFStdErr( \
  239.         "Overall %d files read (%ld entries accepted, %ld rejected).\r", \
  240.         (int)(fn_no+1), (long)BibTeX_gt, (long)BibTeX_et); \
  241. (void) FPrintF(&gBlgDesc,  \
  242.         "Overall %d files read (%ld entries accepted, %ld rejected).\r", \
  243.         (int)(fn_no+1), (long)BibTeX_gt, (long)BibTeX_et); \
  244.     } \
  245. }
  246.  
  247. #define DONE(A, B, C, D) { \
  248.     if (verbose) \
  249.         (void)FPrintFStdErr( "done (%ld %s, %ld %s).\r", \
  250.                       (long)(A), (B), (long)(C), (D)); \
  251.     (void) FPrintF(&gBlgDesc, "done (%ld %s, %ld %s).\r", \
  252.                   (long)(A), (B), (long)(C), (D)); \
  253. }
  254.  
  255. extern void             *chkalloc (size_t size, size_t alignment_size);
  256. extern void             chkfree (void);
  257. extern void *ptohrealloc(short reset);
  258. extern void unlockhandles(void);
  259. extern void lockhandles(void);
  260. extern void cede_time(void);
  261.  
  262. extern FileDesc        gBstDesc;
  263. extern FileDesc        gAuxDesc;
  264. extern FileDesc        gBibDesc;
  265. extern FileDesc        gBlgDesc;
  266. extern FileDesc        gBblDesc;
  267. extern FileDesc        gDbgDesc;
  268.